{% load shorturl %}
{% load ordering %}

<div class="story_container item" id="{{ item.id }}">
    <div id="leftcolumn">
    {% include "control_block.html" %}
    {% include "messages.html" %}
        <div id="story_container">
        <div id="story_body">
            <input type="hidden" name="airtime_current" class="airtime_current"
                   value="{{ item.airtime_left }}">
            <div id="story_info">
                <div id="story_message">{{ item.message }}</div>
                <div id="story_photo">
                    {% if chapter %}
                        <a href="{% url item_filter chapter item.slug %}">
                    {% else %}
                        <a href="{{ item.get_absolute_url }}">
                    {% endif %}
                    {% with image=item.get_big_image %}
                        {% if image %}
                            <img src="{{ image }}"/>
                        {% else %}
                            <img src="{{STATIC_URL}}images/blank.png"/>
                        {% endif %}
                    {% endwith %}
                    </a>
                </div>
                <div id="story_actions_container">
                    <div class="progressbar">
                        {% with ies=item.item_ies_ranges %}
                            {% for i in ies|first %}
                                <span class="blue_bull">&bull;</span>
                            {% endfor %}
                            {% for i in ies|last %}
                                <span class="gray_bull">&bull;</span>
                            {% endfor %}
                        {% endwith %}
                    </div>
                    <div class="user_actions">
                        {% if not item.slumped %}
                            <div>
                                {% if user.is_authenticated %}
                                    <a class="comments" href="#comments{{ item.id }}">Comment</a>
                                {% else %}
                                    <a class="auth_required" href="/">Comment</a>
                                {% endif %}
                            </div>
                            <div>
                                {% if user.is_authenticated %}
                                    {% if user in item.users_like_it %}
                                        <span class="gray">You liked it</span>
                                    {% else %}
                                        <form class="like_form" id="like_form{{ item.id }}"
                                              method="POST" action="/item/like/story/">
                                            {% csrf_token %}
                                            <input type="hidden" name="item" value="{{ item.id }}">
                                            {% if profile_user %}
                                                <input type="hidden" name="profile" value="{{ profile_user.id }}">
                                            {% endif %}
                                            <input type="submit" class="button_as_link" value="Like">
                                        </form>
                                    {% endif %}
                                {% else %}
                                    <a class="auth_required" href="/">Like</a>
                                {% endif %}
                            </div>
                            <div>
                                {% if user.is_authenticated %}
                                    <a class="share" href="#share{{ item.id }}">Share</a>
                                {% else %}
                                    <a class="auth_required" href="/">Share</a>
                                {%  endif %}
                            </div>
                        {% endif %}
                        {% if item.created_by == user %}
                            <div>
                                <form class="delete_form" id="delete_form{{ item.id }}"
                                      method="POST" action="/item/delete/story/">
                                    {% csrf_token %}
                                    <input type="hidden" name="item" value="{{ item.id }}">
                                    <input type="submit" class="button_as_link" value="Delete">
                                </form>
                            </div>
                        {% endif %}
                    </div>
                </div>
                <div id="story_description">{{ item.description }}</div>
                <div id="story_bottom_line">
                    {% with time_left=item.time_expired|timeuntil %}
                        {% if time_left == '0 minutes'%}
                            {% if item.slumped %}
                                    <span class="gray">OFFLINE</span>
                            {% else %}
                                <span>less than 1 minute left</span>
                            {% endif %}
                        {% else %}
                            <span>{{ time_left }} left</span>
                        {% endif %}
                    {%  endwith %}
                    {% with count=item.actions_total_visitors %}
                        {% if count %}
                            &nbsp;<strong>&bull;</strong>&nbsp;<a class="responses" href="#responses{{ item.id }}">
                                View {{ count }} response{% if count > 1 %}s{% endif %}
                            </a>
                            <span class="hidden"><div class="triangle_blue"></div></span>
                        {% else %}
                            {% if not item.slumped %}
                                {% if user.is_authenticated %}
                                    <a class="comments" href="#comments{{ item.id }}">
                                {% else %}
                                    <a class="auth_required right" href="/">
                                {% endif %}
                                Add your comment</a>
                            {% endif %}
                        {% endif %}
                    {% endwith %}
                    {% if not item.slumped and item.created_by == user %}
                        <strong>&bull;</strong>&nbsp;
                        {% if item.airtime_left %}
                            <a class="airtime" href="#airtime{{ item.id }}">
                                Airtime+</a>
                        {% else %}
                            <span class="gray">Airtime</span>
                        {%  endif %}
                    {% endif %}
                </div>
            </div>

            {% if item.created_by == user and not item.slumped %}
                <div class="airtime_div hidden_actions" id="airtime{{ item.id }}">
                    <form class="airtime_form" id="airtime_form{{ item.id }}" method="POST" action="/item/airtime/story/">
                        {% csrf_token %}
                        <input type="hidden" name="item" value="{{ item.id }}">
                        {% if profile_user %}
                            <input type="hidden" name="profile" value="{{ profile_user.id }}">
                        {% endif %}
                        {% with airtime_left=item.airtime_left %}
                            <input type="hidden" name="count" class="airtime_count"
                                   value="{% if airtime_left > 0 %}1{% else %}0{% endif %}">
                            <div class="add">Add&nbsp;</div>
                            <div class=counter>
                                <div class="btn_less"></div>
                                <div class="airtime_amount">{% if airtime_left > 0 %}1{% else %}0{% endif %}</div>
                                <div class="btn_more"></div>
                                <div class="to_this_item">&nbsp;airtime to this item</div>
                            </div>
                            <input type="submit" class="submit_button airtime_button"
                                   value="Add" {% if airtime_left == 0 %}disabled="1"{% endif %}>
                        {% endwith %}
                    </form>
                </div>
            {% endif %}

            <div class="comment_div hidden_actions" id="comments{{ item.id }}" style="display: block;">
                {% if not item.slumped and user.is_authenticated %}
                    <form class="comment_form" id="comment_form{{ item.id }}" method="POST" action="/comment/submit/story/">
                        {% csrf_token %}
                        <input type="hidden" name="item" value="{{ item.id }}">
                        <input type="text" name="comment" class="comment_text" placeholder="Write a comment...">
                        {% if profile_user %}
                            <input type="hidden" name="profile" value="{{ profile_user.id }}">
                        {% endif %}
                        {% if user.is_authenticated %}
                            <input type="submit" class="submit_button comment_button" value="Comment">
                        {% else %}
                            <input type="submit" class="submit_button comment_button auth_required"
                                   value="Comment">
                        {% endif %}
                    </form>
                {% endif %}
                <div class="responses" id="responses{{ item.id }}" style="display: block;">
                    {% include "story_responses.html" %}
                </div>
            </div>
            {% if user.is_authenticated %}
                {% if not item.slumped %}
                <div class="share_div hidden_actions" id="share{{ item.id }}">
                    {% if user.get_facebook_token %}
                        <a class="facebook_share share_picture" id="facebook_share_{{ item.id }}"
                           href="#facebook{{ item.id }}">
                    {% else %}
                        <a class="share_picture" id="facebook_share_{{ item.id }}"
                        href="/associate/facebook/?next={% url share_open 'facebook' item.id %}" target="_blank">
                    {% endif %}
                            <span class="icon_facebook"></span>
                            <span class="share_label">Share</span>
                        </a>
                    {% if user.get_twitter_tokens %}
                        <a class="twitter_tweet share_picture" id="twitter_share_{{ item.id }}"
                         href="#twitter{{ item.id }}">
                    {% else %}
                        <a class="share_picture" id="twitter_share_{{ item.id }}"
                        href="/associate/twitter/?next={% url share_open 'twitter' item.id %}" target="_blank">
                    {% endif %}
                            <span class="icon_twitter"></span>
                            <span class="share_label">Tweet</span>
                        </a>
                    <a href="mailto:?subject=Just went live! {{ item.message }}&amp;body=Check out this story on 8minut.es: {{ item.message }}%0A%0A{% shorturl item %}" target="_blank" title="[GMCP] Compose a new mail to " onclick="window.open('https://mail.google.com/mail/?view=cm&amp;fs=1&amp;tf=1&amp;to=&amp;su=Just%20went%20live!%20{{ item.message }}&amp;body=Check%20out%20this%20story%20on%208minut.es:%20{{ item.message }}%0A{% shorturl item %}%0A%0AHurry%20Up!%20Time%20is%20running%20out%20on%20this%20item','Compose new message','width=640,height=480');return false" rel="noreferrer">
                        <span class="icon_email"></span>
                        <span class="share_label">Email</span>
                    </a>
                    {% include "facebook_share.html" %}
                    {% include "twitter_share.html" %}
                </div>
                {% endif %}
            {% endif %}
            <div class="clearfix"></div>
        </div>
    </div>
</div>
<div id="rightcolumn">
    {% include "story_right.html" %}
</div>
<div class="clearfix"></div>
</div>
{% include "engage_login.html" %}
